package com.systop.supervise.controller;
import com.systop.common.pojo.course_library;
import com.systop.common.pojo.elective_course;
import com.systop.common.util.ResponseResult;
import com.systop.supervise.service.CourselibraryService;
import com.systop.supervise.service.elective_courseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
public class elective_courseController {
    @Autowired
    private elective_courseService electivecourseService;
    @Autowired
    private CourselibraryService courselibraryService;
    //修改
    @RequestMapping(value = "/elcourupdate", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult elcourupdate(@RequestParam(value = "elective_course_id") String elective_course_id,
                                       @RequestParam(value = "course_id") String course_id,
                                       @RequestParam(value = "tno") String tno,
                                       @RequestParam(value = "college_name") String college_name,
                                       @RequestParam(value = "restricted_grade") String restricted_grade,
                                       @RequestParam(value = "time") String time,
                                       @RequestParam(value = "know") String know,
                                       @RequestParam(value = "place") String place,
                                       @RequestParam(value = "max_number") String max_number,
                                       @RequestParam(value = "min_number") String min_number,
                                       @RequestParam(value = "current_number") String current_number,
                                       @RequestParam(value = "remark") String remark) {
        elective_course e =new elective_course();
        int electivecourseid1 = Integer.parseInt(elective_course_id);
        e.setElective_course_id(electivecourseid1);
        int course_id1 = Integer.parseInt(course_id);
        e.setCourse_id(course_id1);
        e.setTno(tno);
        e.setCollege_name(college_name);
        e.setRestricted_grade(restricted_grade);
        e.setTime(time);
        e.setKnow(know);
        e.setPlace(place);
        int max_number1 = Integer.parseInt(max_number);
        e.setMax_number(max_number1);
        int min_number1 = Integer.parseInt(min_number);
        e.setMin_number(min_number1);
        int current_number1 = Integer.parseInt(current_number);
        e.setCurrent_number(current_number1);
        e.setRemark(remark);
        int i = electivecourseService.elcourpdate(e);
        if (i == 0) {
            return ResponseResult.build(500, "修改失败");
        } else {
            return ResponseResult.build(200, "修改成功",e);
        }
    }
    //添加
    @RequestMapping(value = "/elcouradd", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult eelcouradd(@RequestParam(value = "course_id") String course_id,@RequestParam(value = "tno") String tno,@RequestParam(value = "college_name") String college_name, @RequestParam(value = "restricted_grade") String restricted_grade, @RequestParam(value = "time") String time, @RequestParam(value = "know") String know, @RequestParam(value = "place") String place, @RequestParam(value = "max_number") String max_number, @RequestParam(value = "min_number") String min_number, @RequestParam(value = "current_number") String current_number,@RequestParam(value = "remark") String remark) {
        System.out.println("course_id-"+course_id+"tno-"+tno+"college_name-"+college_name+"restricted_grade-"+restricted_grade+"time-"+time+"know-"+know+"place-"+place+"max_number-"+max_number+"min_number-"+min_number+"current_number-"+current_number+"remark-"+remark);
        elective_course e =new elective_course();
        int course_id1 = Integer.parseInt(course_id);
        e.setCourse_id(course_id1);
        e.setTno(tno);
        e.setCollege_name(college_name);
        e.setRestricted_grade(restricted_grade);
        e.setTime(time);
        e.setKnow(know);
        e.setPlace(place);
        int max_number1 = Integer.parseInt(max_number);
        e.setMax_number(max_number1);
        int min_number1 = Integer.parseInt(min_number);
        e.setMin_number(min_number1);
        int current_number1 = Integer.parseInt(current_number);
        e.setCurrent_number(current_number1);
        e.setRemark(remark);
        int i = electivecourseService.eelcouradd(e);
        if (i == 0) {
            return ResponseResult.build(500, "添加失败");
        } else {
            return ResponseResult.build(200, "添加成功",e);
        }
    }
    //查看全部
    @RequestMapping(value = "/elcourall", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult elcourall(){
        List<elective_course> list = electivecourseService.elcourall();
        if (list == null) {
            return ResponseResult.build(500, "查询失败");
        } else {
            return ResponseResult.build(200, "查询成功",list);
        }
    }
    //根据id查看
    @RequestMapping(value = "/elcourid", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult elcourid(String elective_course_id){
        int electivecourseid1 = Integer.parseInt(elective_course_id);
        elective_course e = electivecourseService.elcourid(electivecourseid1);
        if (e == null) {
            return ResponseResult.build(500, "查询失败");
        } else {
            return ResponseResult.build(200, "查询成功",e);
        }
    }
    //根据id查看LIst类型
    @RequestMapping(value = "/elcourid1", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult elcourid1(String elective_course_id){
        int electivecourseid1 = Integer.parseInt(elective_course_id);
        List<elective_course> list = electivecourseService.elcourid1(electivecourseid1);
        if (list == null) {
            return ResponseResult.build(500, "查询失败");
        } else {
            return ResponseResult.build(200, "查询成功",list);
        }
    }
    //根据id查看删除
    @RequestMapping(value = "/elcourdel", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult elcourdel(String elective_course_id){
        int electivecourseid1 = Integer.parseInt(elective_course_id);
       int i = electivecourseService.elcourdel(electivecourseid1);
        if (i == 0) {
            return ResponseResult.build(500, "删除失败");
        } else {
            return ResponseResult.build(200, "删除成功",i);
        }
    }
    //查看课程的详细信息
    @RequestMapping(value = "/elcourxiangqing", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult elcourxiangqing(String elective_course_id){
        int electivecourseid1 = Integer.parseInt(elective_course_id);
        elective_course e = electivecourseService.elcourid(electivecourseid1);
        List<course_library> list= courselibraryService.course_libraryIdlist( e.getCourse_id());
        if (list == null) {
            return ResponseResult.build(500, "查询失败");
        } else {
            return ResponseResult.build(200, "查询成功",list);
        }
    }
    //查看tno课程
    @RequestMapping(value = "/elcourtno", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult elcourtno(String tno){
        List<elective_course> list= electivecourseService.elcourtno(tno);
        if (list == null) {
            return ResponseResult.build(500, "查询失败");
        } else {
            return ResponseResult.build(200, "查询成功",list);
        }
    }


}
